#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main()
{
	int fd = open("a.txt", O_RDONLY ,0666 );
	if(fd == -1) perror("open") , exit(-1);

	struct flock lock ;
	lock.l_type = F_WRLCK;
	lock.l_whence = SEEK_SET;
	lock.l_start = 3;
	lock.l_len = 10 ;
	lock.l_pid = -1;	
	int res = fcntl(fd , F_SETLKW , &lock);	
	if(res != -1)
		printf("锁定成功\n");
	else
		printf("锁定失败\n");
	sleep(10);
}
